cd "directory"

/*New Applications*/

use "solar.dta", clear
gen date_new = date(appreceiveddate, "YMD") if precedingid == ""
format date_new %td
gen date_add = date(appreceiveddate, "YMD") if precedingid != ""
format date_add %td
gen date_end = date(decommissioneddate, "YMD") if applicationstatus == "Decommissioned"
format date_end %td

gen year = year(date_new)
gen month = month(date_new)
gen ym = ym(year, month)
format ym %tm

ren systemsizeac area
gen log_area = log(area)

merge m:1 zip using "zip_zcta_crosswalk"
drop if _merge!= 3
drop _merge

merge m:1 zcta using "zcta_county_crosswalk.dta"
drop if _merge != 3
drop _merge

gen D_end = date_end ! = .
gen D_add = date_add ! = .

egen county_year  = group(fips year)

cd "results"

/*Table 9*/

reghdfe area EV if year>=2011 & year<=2016, absorb(zcta year) cluster(zcta)
outreg2 using result_EV_area, replace keep(EV) nocon label tex(frag) ct(Solar Capacity) addtext(Year FEs, YES, County-Year FEs, NO, Date FEs, NO, ZCTA FEs, YES) nonotes
reghdfe area EV if year>=2011 & year<=2016, absorb(zcta county_year) cluster(zcta)
outreg2 using result_EV_area, append keep(EV) nocon label tex(frag) ct(Solar Capacity) addtext(Year FEs, NO, County-Year FEs, YES, Date FEs, NO, ZCTA FEs, YES) nonotes
reghdfe area EV if year>=2011 & year<=2016, absorb(zcta date_new county_year) cluster(zcta)
outreg2 using result_EV_area, append keep(EV) nocon label tex(frag) ct(Solar Capacity) addtext(Year FEs, NO, County-Year FEs, YES, Date FEs, YES, ZCTA FEs, YES) nonotes
reghdfe log_area EV if year>=2011 & year<=2016, absorb(zcta year) cluster(zcta)
outreg2 using result_EV_area, append keep(EV) nocon label tex(frag) ct(log(Solar Capacity)) addtext(Year FEs, YES, County-Year FEs, NO, Date FEs, NO, ZCTA FEs, YES) nonotes
reghdfe log_area EV if year>=2011 & year<=2016, absorb(zcta county_year) cluster(zcta)
outreg2 using result_EV_area, append keep(EV) nocon label tex(frag) ct(log(Solar Capacity)) addtext(Year FEs, NO, County-Year FEs, YES, Date FEs, NO, ZCTA FEs, YES) nonotes
reghdfe log_area EV if year>=2011 & year<=2016, absorb(zcta date_new county_year) cluster(zcta)
outreg2 using result_EV_area, append keep(EV) nocon label tex(frag) ct(log(Solar Capacity)) addtext(Year FEs, NO, County-Year FEs, YES, Date FEs, YES, ZCTA FEs, YES) nonotes

reghdfe area EV if year>2016 & year<2020, absorb(zcta year) cluster(zcta)
outreg2 using result_EV_area_post, replace keep(EV) nocon label tex(frag) ct(Solar Capacity) addtext(Year FEs, YES, County-Year FEs, NO, Date FEs, NO, ZCTA FEs, YES) nonotes
reghdfe area EV if year>2016 & year<2020, absorb(zcta county_year) cluster(zcta)
outreg2 using result_EV_area_post, append keep(EV) nocon label tex(frag) ct(Solar Capacity) addtext(Year FEs, NO, County-Year FEs, YES, Date FEs, NO, ZCTA FEs, YES) nonotes
reghdfe area EV if year>2016 & year<2020, absorb(zcta date_new county_year) cluster(zcta)
outreg2 using result_EV_area_post, append keep(EV) nocon label tex(frag) ct(Solar Capacity) addtext(Year FEs, NO, County-Year FEs, YES, Date FEs, YES, ZCTA FEs, YES) nonotes
reghdfe log_area EV if year>2016 & year<2020, absorb(zcta year) cluster(zcta)
outreg2 using result_EV_area_post, append keep(EV) nocon label tex(frag) ct(log(Solar Capacity)) addtext(Year FEs, YES, County-Year FEs, NO, Date FEs, NO, ZCTA FEs, YES) nonotes
reghdfe log_area EV if year>2016 & year<2020, absorb(zcta county_year) cluster(zcta)
outreg2 using result_EV_area_post, append keep(EV) nocon label tex(frag) ct(log(Solar Capacity)) addtext(Year FEs, NO, County-Year FEs, YES, Date FEs, NO, ZCTA FEs, YES) nonotes
reghdfe log_area EV if year>2016 & year<2020, absorb(zcta date_new county_year) cluster(zcta)
outreg2 using result_EV_area_post, append keep(EV) nocon label tex(frag) ct(log(Solar Capacity)) addtext(Year FEs, NO, County-Year FEs, YES, Date FEs, YES, ZCTA FEs, YES) nonotes

cd "directory"

/*Subsequent Applications*/

use "solar.dta", clear
keep if precedingid != ""
ren precedingid match_id
gen date_add = date(appreceiveddate, "YMD")
format date_add %td
ren systemsizeac area_add
gen log_area_add = log(area_add)
ren EV EV_add
keep applicationid match_id area_add log_area_add EV_add date_add
save solar_application_add, replace

use "solar.dta", clear
ren applicationid match_id
merge 1:1 match_id using solar_application_add
drop if _merge != 3
drop _merge
gen EV_diff = EV_add-EV
gen year = year(date_add)
ren systemsizeac area
gen log_area = log(area)

merge m:1 zip using "zip_zcta_crosswalk"
drop if _merge!= 3
drop _merge

merge m:1 zcta using "zcta_county_crosswalk.dta"
drop if _merge != 3
drop _merge

egen county_year = group(fips year)

label var EV_diff "Adopt EV"
label var area "Initial Solar Capacity"
label var log_area "log(Initial Solar Capacity)"

cd "results"

/*Table 10*/

reghdfe area_add EV_diff area if year>=2011 & year<=2016, absorb(zcta year) cluster(zcta) nocon
outreg2 using result_EV_area_add, replace keep(EV_diff area) nocon label tex(frag) ct(Solar Capacity) addtext(Year FEs, YES, County-Year FEs, NO, Date FEs, NO, ZCTA FEs, YES) nonotes
reghdfe area_add EV_diff area if year>=2011 & year<=2016, absorb(zcta county_year) cluster(zcta) nocon
outreg2 using result_EV_area_add, append keep(EV_diff area) nocon label tex(frag) ct(Solar Capacity) addtext(Year FEs, NO, County-Year FEs, YES, Date FEs, NO, ZCTA FEs, YES) nonotes
reghdfe area_add EV_diff area if year>=2011 & year<=2016, absorb(zcta date_add county_year) cluster(zcta) nocon
outreg2 using result_EV_area_add, append keep(EV_diff area) nocon label tex(frag) ct(Solar Capacity) addtext(Year FEs, NO, County-Year FEs, YES, Date FEs, YES, ZCTA FEs, YES) nonotes
reghdfe log_area_add EV_diff log_area if year>=2011 & year<=2016, absorb(zcta year) cluster(zcta) nocon
outreg2 using result_EV_area_add, append keep(EV_diff log_area) nocon label tex(frag) ct(log(Solar Capacity)) addtext(Year FEs, YES, County-Year FEs, NO, Date FEs, NO, ZCTA FEs, YES) nonotes
reghdfe log_area_add EV_diff log_area if year>=2011 & year<=2016, absorb(zcta county_year) cluster(zcta) nocon
outreg2 using result_EV_area_add, append keep(EV_diff log_area) nocon label tex(frag) ct(log(Solar Capacity)) addtext(Year FEs, NO, County-Year FEs, YES, Date FEs, NO, ZCTA FEs, YES) nonotes
reghdfe log_area_add EV_diff log_area if year>=2011 & year<=2016, absorb(zcta date_add county_year) cluster(zcta) nocon
outreg2 using result_EV_area_add, append keep(EV_diff log_area) nocon label tex(frag) ct(log(Solar Capacity)) addtext(Year FEs, NO, County-Year FEs, YES, Date FEs, YES, ZCTA FEs, YES) nonotes

reghdfe area_add EV_diff area if year>2016 & year<2020, absorb(zcta year) cluster(zcta) nocon
outreg2 using result_EV_area_add_post, replace keep(EV_diff area) nocon label tex(frag) ct(Solar Capacity) addtext(Year FEs, YES, County-Year FEs, NO, Date FEs, NO, ZCTA FEs, YES) nonotes
reghdfe area_add EV_diff area if year>2016 & year<2020, absorb(zcta county_year) cluster(zcta) nocon
outreg2 using result_EV_area_add_post, append keep(EV_diff area) nocon label tex(frag) ct(Solar Capacity) addtext(Year FEs, NO, County-Year FEs, YES, Date FEs, NO, ZCTA FEs, YES) nonotes
reghdfe area_add EV_diff area if year>2016 & year<2020, absorb(zcta date_add county_year) cluster(zcta) nocon
outreg2 using result_EV_area_add_post, append keep(EV_diff area) nocon label tex(frag) ct(Solar Capacity) addtext(Year FEs, NO, County-Year FEs, YES, Date FEs, YES, ZCTA FEs, YES) nonotes
reghdfe log_area_add EV_diff log_area if year>2016 & year<2020, absorb(zcta year) cluster(zcta) nocon
outreg2 using result_EV_area_add_post, append keep(EV_diff log_area) nocon label tex(frag) ct(log(Solar Capacity)) addtext(Year FEs, YES, County-Year FEs, NO, Date FEs, NO, ZCTA FEs, YES) nonotes
reghdfe log_area_add EV_diff log_area if year>2016 & year<2020, absorb(zcta county_year) cluster(zcta) nocon
outreg2 using result_EV_area_add_post, append keep(EV_diff log_area) nocon label tex(frag) ct(log(Solar Capacity)) addtext(Year FEs, NO, County-Year FEs, YES, Date FEs, NO, ZCTA FEs, YES) nonotes
reghdfe log_area_add EV_diff log_area if year>2016 & year<2020, absorb(zcta date_add county_year) cluster(zcta) nocon
outreg2 using result_EV_area_add_post, append keep(EV_diff log_area) nocon label tex(frag) ct(log(Solar Capacity)) addtext(Year FEs, NO, County-Year FEs, YES, Date FEs, YES, ZCTA FEs, YES) nonotes
